<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="/favicon.ico" >
<link rel="Shortcut Icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="__HUI__/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="__HUIADMIN__/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="__HUIADMIN__/skin/blue/skin.css" id="blue" />
<link rel="stylesheet" type="text/css" href="__HUIADMIN__/common.css" />
<script src="__SFDP__/lib/jquery-1.12.4.js"></script>
<script src="__SFDP__/lib/layer/2.4/layer.js"></script>
<script src="__SFDP__/js/sfdp.fun.js"></script>
<link rel="stylesheet" href="__SFDP__/css/sfdp.common.css" />
<script type="text/javascript" src="__HUI__/js/H-ui.min.js"></script>
<script type="text/javascript" src="__HUIADMIN__/js/H-ui.admin.js"></script>
<title>Sfdp</title>
</head>
<body>
<div class="page-container">

    <div class="cl pd-5 bk-gray">
		  <span class="l">
           <a onClick='add_fun()' class="btn btn-primary radius">创建</a>
        </span>
        <span class="r pt-5 pr-5">
            共有数据 ：<strong>{:count($list)}</strong> 条
        </span>
    </div>
	<table class="table table-border table-bordered table-bg">
		<thead>
			<tr class="text-c">
				<th width="150">编码</th>
				<th width="150">标题</th>
				<th width="100">函数名</th>
				<th width="80">发布时间</th>
				<th width="50">添加人</th>
				<th width="50">状态</th>
				<th width="200">操作</th>
			</tr>
		</thead>
		<tbody>
			{volist name='list' id='k'}
			<tr class="text-c">
				<td>{$k.bill}</td>
				<td>{$k.title}</td>
				<td>{$k.fun_name}</td>
				<td>{$k.add_time|date='Y-m-d H:i'}</td>
				<td>{$k.add_user}</td>
				<td>{eq name='k.status' value='0'}编辑中{else/}已启用{/eq}</td>
				<td class="text-l">
				<div class="btn-group">
					<a onClick="add_fun('{$k.title}','{$k.fun_name}','{$k.function}','{$k.id}')"	class="btn  radius size-S">编辑</a>
				</div>
				</td>
			</tr>
			{/volist}
		</tbody>
	</table>
</div>
<div class="page-bootstrap">{$list|raw}</div>

</body>
</html>
<script>
function add_fun(title='',name='',fun='',id=''){
	var html ='<form action="" method="post" name="form" id="form">'+
			  '<table id="table_view"><tr><td width="60px">函数标题</td><td><input type="text" id="title" value="'+title+'"></td></tr>'+
			  '<tr><td>函数名称</td><td><input type="text" id="name" value="'+name+'"></td></tr>'+
			  '<tr><td>填写函数</td><td><textarea placeholder="请填写SQL代码！" id="fun" type="text/plain" style="width:100%;height:100px;">'+fun+'</textarea></td></tr><tr><td colspan=2><a class="btn  radius size-S" onclick="save_fun('+id+')">提交</a></td></tr></table></form>';
		layer.open({
		  type: 1,
		  area: ['520px', '340px'], //宽高
		  content: html
		});
}
function save_fun(id){
	var NameExp = /^(?!_)(?!.*?_$)[a-z_]+$/;
	var title = $('#title').val();
	var name = $('#name').val();
	if(!NameExp.test(name)){
		commonfun.ShowTip('函数名称只能为英文小写字母加下划线组合！');
		return;
	}
	var fun = $('#fun').val();
	var url = "{:url('/index/sfdp/sfdp_fun_save')}";
	commonfun.sAjax(url,{title:title,name:name,fun:fun,id:id});
	
}
</script>